home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Online / NNTPd / support / nntp_awk < prev    next >
Text File  |  2002-11-01  |  13KB  |  462 lines

  1. # an awk script 
  2. # an NNTP log summary report generator
  3. #
  4. # NOTE: for systems that are not as yet using the new 4.3 BSD syslog
  5. # (and therefore have nntp messages lumped with everything else), it
  6. # would be best to invoke this script thusly:
  7. #
  8. #    egrep nntp syslog.old | awk -f nntp_awk > report_of_the_week
  9. #
  10. # because this script will include in the report all messages in the log
  11. # that it does not recognize (on the assumption that they are errors to
  12. # be dealt with by a human).
  13. #
  14. # Erik E. Fair <fair@ucbarpa.berkeley.edu>
  15. # May 17, 1986 - Norwegian Independence Day
  16. #
  17. # Recognize some new things - February 22, 1987
  18. # Erik E. Fair <fair@ucbarpa.berkeley.edu>
  19. #
  20. # fix "xmt is not an array" bug - March 11, 1987
  21. # Change Elapsed/CPU fields to break out time values, HH:MM:SS
  22. # Erik E. Fair <fair@ucbarpa.berkeley.edu>
  23. #
  24. # Add reporting for newnews commands - August 27, 1987
  25. # Erik E. Fair <fair@ucbarpa.berkeley.edu>
  26. #
  27. # Add nntpxmit connection attempt counting/reporting - December 7, 1987
  28. # Erik E. Fair <fair@ucbarpa.berkeley.edu>
  29. #
  30. # Fixed bug in explorers couting - November 7, 1989
  31. # Stan Barber <sob@bcm.tmc.edu>
  32. #
  33. BEGIN{
  34.     readers = 0;
  35.     transmit = 0;
  36.     receive = 0;
  37.     polled = 0;
  38. }
  39. ### Skip stderr reports from rnews
  40. {
  41.     n = split($6, path, "/");
  42.     if (path[n] == "rnews:") next;
  43.     n = split($7, path, "/");
  44.     if (path[n] == "rnews") next;
  45.     host = $6;
  46. }
  47. $7 == "group" {
  48.     readers = 1;
  49.     ng[$8]++;
  50.     next;
  51. }
  52. $7 == "ihave" {
  53.     receive = 1;
  54.     rec[host]++;
  55.     if ($9 == "accepted") {
  56.         rec_accept[host]++;
  57.         if ($10 == "failed") rec_failed[host]++;
  58.     } else if ($9 == "rejected") rec_refuse[host]++;
  59.     next;
  60. }
  61. # this is from version 1.4 of nntpd
  62. $7 == "ihave_stats" {
  63.     receive = 1;
  64.     rec[host] += $9 + $11 + $13;
  65.     rec_accept[host] += $9;
  66.     rec_refuse[host] += $11;
  67.     rec_failed[host] += $13;
  68.     next;
  69. }
  70. $7 == "connect" {
  71.     systems[host]++;
  72.     next;
  73. }
  74. # nntpxmit connection errors
  75. # Ooooh! I *wish* awk had N dimensional arrays,
  76. # so I wouldn't have to throw away the error message here!
  77. $7 == "hello:" {
  78.     conn[host]++;
  79.     if ($8 == "Connection" && $9 == "refused")
  80.         rmt_fail[host]++;
  81.     else
  82.         open_fail[host]++;
  83.     next;
  84. }
  85. # we'll get stats from this, don't count conn[]
  86. $7 == "xfer:" {
  87.     open_fail[host]++;
  88. # since these are expected to be few in number, we still print
  89. # the exact error (no "next;" statement here).
  90. }
  91. $7 == "greeted" {
  92.     conn[host]++;
  93.     rmt_fail[host]++;
  94.     next;
  95. }
  96. $7 == "host" && $8 == "unknown" {
  97.     conn[host]++;
  98.     ns_fail[host]++;
  99.     next;
  100. }
  101. # nntpd connection abort - all "broken pipe" right now
  102. $7 == "disconnect:" { next }
  103. # syslogd shit
  104. $7 == "repeated" { next }
  105. # inews shit
  106. $11 == "spooled" { next }
  107. $7 == "exit" {
  108.     if ($8 > 0) readers = 1;
  109.     articles[host] += $8;
  110.     groups[host] += $10;
  111.     next;
  112. }
  113. $7 == "xmit" {
  114.     xmt_cpu[host] += $9 + $11;
  115.     xmt_ela[host] += $13;
  116.     next;
  117. }
  118. $7 == "times" {
  119.     cpu[host] += $9 + $11;
  120.     ela[host] += $13;
  121.     next;
  122. }
  123. $7 == "stats" {
  124.     transmit = 1;
  125.     conn[host]++;
  126.     xmt[host] += $8;
  127.     xmt_accept[host] += $10;
  128.     xmt_refuse[host] += $12;
  129.     xmt_failed[host] += $14;
  130.     next;
  131. }
  132. #
  133. #    For the Nth time, I wish awk had two dimensional associative
  134. #    arrays. I assume that the last request is the same as all the
  135. #    others in this section of logfile.
  136. #
  137. $7 == "newnews" {
  138.     polled = 1;
  139.     poll[host] ++;
  140.     poll_asked[host] = $8;
  141.     next;
  142. }
  143. $7 == "newnews_stats" {
  144.     poll_offered[host] += $9;
  145.     poll_took[host] += $11;
  146.     next;
  147. }
  148. $7 == "post" {
  149.     readers = 1;
  150.     post[host]++;
  151.     next;
  152. }
  153. $7 == "timeout" {
  154.     timeout[host]++;
  155.     timeouts = 1;
  156.     next;
  157. }
  158. $7 == "unrecognized" {
  159.     unknown[host]++;
  160.     curious = 1;
  161. }
  162. ### Print anything that we don't recognize in the report
  163. {
  164.     print;
  165. }
  166. END{
  167.     printf("\n");
  168. ###############################################################################
  169. ### Article Exchange With Peers (other servers) Statistics                  ###
  170. ###############################################################################
  171.     if (transmit || receive || polled)
  172.         printf("NNTP peer article transfers\n\n");
  173.  
  174.     if (polled) for(s in poll) servers[s]++;
  175.     if (receive) for(s in rec) servers[s]++;
  176.     if (transmit) for(s in xmt) servers[s]++;
  177.  
  178.     if (receive) {
  179.         printf("Article Reception (they contact us)\n");
  180.         printf("System                  Offered  Took  Toss  Fail Toss   Elapsed       CPU  Pct\n");
  181.         for(s in rec) {
  182.  
  183.             nrec += rec[s];
  184.             nrec_accept += rec_accept[s];
  185.             nrec_refuse += rec_refuse[s];
  186.             nrec_failed += rec_failed[s];
  187.             nrec_cpu += cpu[s];
  188.             nrec_ela += ela[s];
  189.  
  190.             they_offered = rec[s];
  191.             if (they_offered == 0) they_offered = 1;
  192.             we_toss = (rec_refuse[s] / they_offered) * 100 + 0.5;
  193.  
  194.             e_hours      = ela[s] / 3600;
  195.             e_sec        = ela[s] % 3600;
  196.             e_min        = e_sec / 60;
  197.             e_sec        %= 60;
  198.  
  199.             c_hours      = cpu[s] / 3600;
  200.             c_sec        = cpu[s] % 3600;
  201.             c_min        = c_sec / 60;
  202.             c_sec        %= 60;
  203.  
  204.             tmp = ela[s];
  205.             if (tmp == 0) tmp = 1;
  206.             pct = ((cpu[s] / tmp) * 100.0 + 0.5);
  207.  
  208.             printf("%-25s %5d %5d %5d %5d %3d%% %3d:%02d:%02d %3d:%02d:%02d %3d%%\n", s, rec[s], rec_accept[s], rec_refuse[s], rec_failed[s], we_toss, e_hours, e_min, e_sec, c_hours, c_min, c_sec, pct);
  209.         }
  210.  
  211.         e_hours      = nrec_ela / 3600;
  212.         e_sec        = nrec_ela % 3600;
  213.         e_min        = e_sec / 60;
  214.         e_sec        %= 60;
  215.  
  216.         c_hours      = nrec_cpu / 3600;
  217.         c_sec        = nrec_cpu % 3600;
  218.         c_min        = c_sec / 60;
  219.         c_sec        %= 60;
  220.  
  221.         they_offered = nrec;
  222.         if (they_offered == 0) they_offered = 1;
  223.         we_toss = (nrec_refuse / they_offered) * 100 + 0.5;
  224.  
  225.         if (nrec_ela == 0) nrec_ela = 1;
  226.         pct = ((nrec_cpu / nrec_ela) * 100.0 + 0.5);
  227.  
  228.         printf("\n%-25s %5d %5d %5d %5d %3d%% %3d:%02d:%02d %3d:%02d:%02d %3d%%\n\n", "TOTALS", nrec, nrec_accept, nrec_refuse, nrec_failed, we_toss, e_hours, e_min, e_sec, c_hours, c_min, c_sec, pct);
  229.     }
  230.  
  231. ###############################################################################
  232.     if (polled) {
  233.         printf("Article Transmission (they poll us)\n");
  234.         printf("System                     Conn Offrd  Took   Elapsed       CPU  Pct  Groups\n");
  235.         npoll = 0;
  236.         npoll_offered = 0;
  237.         npoll_took = 0;
  238.         npoll_cpu = 0;
  239.         npoll_ela = 0;
  240.  
  241.         for(s in poll) {
  242.             npoll += poll[s];
  243.             npoll_offered += poll_offered[s];
  244.             npoll_took += poll_took[s];
  245.  
  246.             if (rec[s]) {
  247.                 printf("%-25s %5d %5d %5d  (see Article Reception)  %s\n", s, poll[s], poll_offered[s], poll_took[s], poll_asked[s]);
  248.             } else {
  249.                 npoll_ela += ela[s];
  250.                 npoll_cpu += cpu[s];
  251.  
  252.                 e_hours = ela[s] / 3600;
  253.                 e_sec   = ela[s] % 3600;
  254.                 e_min   = e_sec / 60;
  255.                 e_sec   %= 60;
  256.  
  257.                 c_hours = cpu[s] / 3600;
  258.                 c_sec   = cpu[s] % 3600;
  259.                 c_min   = c_sec / 60;
  260.                 c_sec   %= 60;
  261.  
  262.                 tmp = ela[s];
  263.                 if (tmp == 0) tmp = 1;
  264.                 pct = ((cpu[s] / tmp) * 100.0 + 0.5);
  265.  
  266.                 printf("%-25s %5d %5d %5d %3d:%02d:%02d %3d:%02d:%02d %3d%%  %s\n", s, poll[s], poll_offered[s], poll_took[s], e_hours, e_min, e_sec, c_hours, c_min, c_sec, pct, poll_asked[s]);
  267.             }
  268.         }
  269.         printf("\n%-25s %5d %5d %5d", "TOTALS", npoll, npoll_offered, npoll_took);
  270.         if (npoll_ela > 0 && npoll_cpu > 0) {
  271.  
  272.             e_hours = npoll_ela / 3600;
  273.             e_sec   = npoll_ela % 3600;
  274.             e_min   = e_sec / 60;
  275.             e_sec   %= 60;
  276.  
  277.             c_hours = npoll_cpu / 3600;
  278.             c_sec   = npoll_cpu % 3600;
  279.             c_min   = c_sec / 60;
  280.             c_sec   %= 60;
  281.  
  282.             tmp = npoll_ela;
  283.             if (tmp == 0) tmp = 1;
  284.             pct = ((npoll_cpu / tmp) * 100.0 + 0.5);
  285.  
  286.             printf(" %3d:%02d:%02d %3d:%02d:%02d %3d%%\n\n", e_hours, e_min, e_sec, c_hours, c_min, c_sec, pct);
  287.         } else
  288.             printf("\n\n");
  289.     }
  290.  
  291. ###############################################################################
  292.     if (transmit) {
  293.         printf("Article Transmission (we contact them)\n");
  294.         printf("System                    Offrd  Took  Toss  Fail  Pct   Elapsed       CPU  Pct\n");
  295.         for(s in xmt) {
  296.             we_offered = xmt[s];
  297.             if (we_offered == 0) we_offered = 1;
  298.             they_toss = (xmt_refuse[s] / we_offered) * 100 + 0.5;
  299.  
  300.             e_hours = xmt_ela[s] / 3600;
  301.             e_sec   = xmt_ela[s] % 3600;
  302.             e_min   = e_sec / 60;
  303.             e_sec   %= 60;
  304.  
  305.             c_hours = xmt_cpu[s] / 3600;
  306.             c_sec   = xmt_cpu[s] % 3600;
  307.             c_min   = c_sec / 60;
  308.             c_sec   %= 60;
  309.  
  310.             elapsed = xmt_ela[s];
  311.             if (elapsed == 0) elapsed = 1;
  312.             pct = ((xmt_cpu[s] / elapsed) * 100.0 + 0.5);
  313.  
  314.             printf("%-25s %5d %5d %5d %5d %3d%% %3d:%02d:%02d %3d:%02d:%02d %3d%%\n", s, xmt[s], xmt_accept[s], xmt_refuse[s], xmt_failed[s], they_toss, e_hours, e_min, e_sec, c_hours, c_min, c_sec, pct);
  315.  
  316.             nxmt        += xmt[s];
  317.             nxmt_accept += xmt_accept[s];
  318.             nxmt_refuse += xmt_refuse[s];
  319.             nxmt_failed += xmt_failed[s];
  320.             nxmt_ela    += xmt_ela[s];
  321.             nxmt_cpu    += xmt_cpu[s];
  322.         }
  323.  
  324.         we_offered = nxmt;
  325.         if (we_offered == 0) we_offered = 1;
  326.         they_toss = (nxmt_refuse / we_offered) * 100 + 0.5;
  327.  
  328.         e_hours = nxmt_ela / 3600;
  329.         e_sec   = nxmt_ela % 3600;
  330.         e_min   = e_sec / 60;
  331.         e_sec   %= 60;
  332.  
  333.         c_hours = nxmt_cpu / 3600;
  334.         c_sec   = nxmt_cpu % 3600;
  335.         c_min   = c_sec / 60;
  336.         c_sec   %= 60;
  337.  
  338.         if (nxmt_ela == 0) nxmt_ela = 1;
  339.         pct = ((nxmt_cpu / nxmt_ela) * 100.0 + 0.5);
  340.  
  341.         printf("\n%-25s %5d %5d %5d %5d %3d%% %3d:%02d:%02d %3d:%02d:%02d %3d%%\n\n", "TOTALS", nxmt, nxmt_accept, nxmt_refuse, nxmt_failed, they_toss, e_hours, e_min, e_sec, c_hours, c_min, c_sec, pct);
  342.  
  343.         printf("Transmission Connection Attempts         ------errors-------\n");
  344.         printf("System                     Conn    OK    NS   Net   Rmt  Pct\n");
  345.         for(s in xmt) {
  346.             tot = conn[s];
  347.             if (tot == 0) tot = 1;
  348.             errs = rmt_fail[s] + ns_fail[s] + open_fail[s];
  349.             ok = (conn[s] - errs);
  350.             printf("%-25s %5d %5d %5d %5d %5d %3d%%\n", s, conn[s], ok, ns_fail[s], open_fail[s], rmt_fail[s], (100.0 * errs / tot + 0.5));
  351.             ct_tot += conn[s];
  352.             ct_ok  += ok;
  353.             ct_ns  += ns_fail[s];
  354.             ct_net += open_fail[s];
  355.             ct_rmt += rmt_fail[s];
  356.         }
  357.         tot = ct_tot;
  358.         if (tot == 0) tot = 1;
  359.         errs = ct_ns + ct_net + ct_rmt;
  360.         printf("\n%-25s %5d %5d %5d %5d %5d %3d%%\n\n", "TOTALS", ct_tot, ct_ok, ct_ns, ct_net, ct_rmt, (100.0 * errs / tot + 0.5));
  361.     }
  362.  
  363. ###############################################################################
  364. ### Article Readership Statistics                                           ###
  365. ###############################################################################
  366.  
  367.     if (readers) {
  368.         printf("NNTP readership statistics\n");
  369.         printf("System                     Conn Articles Groups Post   Elapsed       CPU  Pct\n");
  370.         for(s in systems) {
  371. ###
  372. ### servers are different animals; they don't belong in this part of the report
  373. ###
  374.             if (servers[s] > 0 && groups[s] == 0 && articles[s] == 0)
  375.                 continue;
  376. ###
  377. ### report the curious server pokers elsewhere
  378. ###
  379.             if (groups[s] == 0 && articles[s] == 0 && post[s] == 0) {
  380.                 unknown[s] += systems[s];
  381.                 curious = 1;
  382.                 continue;
  383.             }
  384.  
  385.             nconn += systems[s];
  386.             nart += articles[s];
  387.             ngrp += groups[s];
  388.             npost += post[s];
  389.             ncpu += cpu[s];
  390.             nela += ela[s];
  391.  
  392.             e_hours      = ela[s] / 3600;
  393.             e_sec        = ela[s] % 3600;
  394.             e_min        = e_sec / 60;
  395.             e_sec        %= 60;
  396.  
  397.             c_hours      = cpu[s] / 3600;
  398.             c_sec        = cpu[s] % 3600;
  399.             c_min        = c_sec / 60;
  400.             c_sec        %= 60;
  401.  
  402.             elapsed = ela[s];
  403.             if (elapsed == 0) elapsed = 1;
  404.             pct = ((cpu[s] / elapsed) * 100 + 0.5);
  405.  
  406.             printf("%-25s %5d %8d %6d %4d %3d:%02d:%02d %3d:%02d:%02d %3d%%\n", s, systems[s], articles[s], groups[s], post[s], e_hours, e_min, e_sec, c_hours, c_min, c_sec, pct);
  407.         }
  408.  
  409.         e_hours      = nela / 3600;
  410.         e_sec        = nela % 3600;
  411.         e_min        = e_sec / 60;
  412.         e_sec        %= 60;
  413.  
  414.         c_hours      = ncpu / 3600;
  415.         c_sec        = ncpu % 3600;
  416.         c_min        = c_sec / 60;
  417.         c_sec        %= 60;
  418.  
  419.         if (nela == 0) nela = 1;
  420.         pct = ((ncpu / nela) * 100 + 0.5);
  421.  
  422.         printf("\n%-25s %5d %8d %6d %4d %3d:%02d:%02d %3d:%02d:%02d %3d%%\n\n", "TOTALS", nconn, nart, ngrp, npost, e_hours, e_min, e_sec, c_hours, c_min, c_sec, pct);
  423.     }
  424.  
  425. ###############################################################################
  426.     if (curious) {
  427.         printf("Unknown NNTP server explorers\nSystem                     Conn\n");
  428.         for(s in unknown) {
  429.             printf("%-25s %5d\n", s, unknown[s]);
  430.         }
  431.         printf("\n");
  432.     }
  433. ###############################################################################
  434.     if (timeouts) {
  435.         printf("Server timeouts\n");
  436.         for(s in timeout) {
  437.             printf("%-25s %5d\n", s, timeout[s]);
  438.         }
  439.         printf("\n");
  440.     }
  441. ###############################################################################
  442.     if (readers) {
  443.         for(g in ng) {
  444.             x = length(g);
  445.             if (x > max) max = x;
  446.  
  447.             i = index(g, ".");
  448.             if (i > 0) top = substr(g, 1, i - 1);
  449.             else top = g;
  450.             category[top] += ng[g];
  451.         }
  452.         fmt = sprintf("%%-%ds %%5d\n", max);
  453.  
  454.         printf("Newsgroup Request Counts (by category)\n");
  455.         for(g in category) printf(fmt, g, category[g]);
  456.  
  457.         printf("\nNewsgroup Request Counts (by newsgroup)\n");
  458.         for(g in ng) printf(fmt, g, ng[g]);
  459.         printf("\n");
  460.     }
  461. }
  462.